/*
 * attribute.cpp
 *
 *  Created on: Aug 14, 2013
 *      Author: killerg
 */
#include "../server_deps.h"
#include "../server.h"
#include "attribute.h"
#include "proto_mgr.h"

void att_t::add_mod(int32_t modid, int32_t rate) {
    auto proto = MAProto(AttMod, modid);
    for (int i=0; i<4; ++i) {
        mod_pct(cs::EPetAtt(proto->att[i]), proto->pct[i] * rate, true);
        mod_flat(cs::EPetAtt(proto->att[i]), proto->flat[i] * rate, true);
    }
}

void att_t::dec_mod(int32_t modid, int32_t rate) {
    auto proto = MAProto(AttMod, modid);
    for (int i=0; i<4; ++i) {
        mod_pct(cs::EPetAtt(proto->att[i]), proto->pct[i] * rate, false);
        mod_flat(cs::EPetAtt(proto->att[i]), proto->flat[i] * rate, false);
    }
}

void att_t::add_mods(const list<pair<int32_t, int32_t>> &mods) {
    for (auto itr = mods.begin(); itr != mods.end(); ++itr)
        add_mod(itr->first, itr->second);
}

void att_t::dec_mods(const list<pair<int32_t, int32_t>> &mods) {
    for (auto itr = mods.begin(); itr != mods.end(); ++itr)
        dec_mod(itr->first, itr->second);
}

void att_t::add_mods(const vector<att_mod_t> &mods) {
    for (auto itr = mods.begin(); itr != mods.end(); ++itr) {
        mod_pct(cs::EPetAtt(itr->att), itr->pct_mod, true);
        mod_flat(cs::EPetAtt(itr->att), itr->flat_mod, true);
    }
}

void att_t::dec_mods(const vector<att_mod_t> &mods) {
    for (auto itr = mods.begin(); itr != mods.end(); ++itr) {
        mod_pct(cs::EPetAtt(itr->att), itr->pct_mod, false);
        mod_flat(cs::EPetAtt(itr->att), itr->flat_mod, false);
    }
}

